        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>MathBox class / box2d_html Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="box2d_html" data-type="MathBox">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../box2d_html.html">box2d_html</a> &rsaquo; <a href="../box2d_html/MathBox.html">MathBox</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>MathBox</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<pre class="source">
class MathBox {
  static const double TWO_PI = Math.PI * 2.0;

  MathBox();

  /**
   * Return the distance between the two given vectors, but squared.
   */
  static num distanceSquared(Vector v1, Vector v2) {
    num dx = (v1.x - v2.x);
    num dy = (v1.y - v2.y);
    return dx * dx + dy * dy;
  }

  /**
   * Return the distance between the two given vectors.
   */
  static num distance(Vector v1, Vector v2) {
    return Math.sqrt(distanceSquared(v1, v2));
  }

  /** Returns the closest value to [a] that is in between [low] and [high] */
  static num clamp(num a, num low, num high) {
    return Math.max(low, Math.min(a, high));
  }

  /**
   * Given a value within the range specified by [fromMin] and [fromMax],
   * returns a value with the same relative position in the range specified
   * from [toMin] and [toMax]. For example, given a [val] of 2 in the
   * "from range" of 0-4, and a "to range" of 10-20, would return 15.
   */
  static num translateAndScale(num val, num fromMin, num fromMax, num toMin,
      num toMax) {
    final num mult = (val - fromMin) / (fromMax - fromMin);
    final num res = toMin + mult * (toMax - toMin);
    return res;
  }

  /** Convert from [deg] degrees to radians. */
  static num degToRad(num deg) =&gt; (Math.PI / 180.0) * deg;
  /** Convert from [rad] radians to degrees. */
  static num radToDeg(num rad) =&gt; (180.0 / Math.PI) * rad;
}
</pre>
</div>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="MathBox">
<button class="show-code">Code</button>
new <strong>MathBox</strong>() <a class="anchor-link" href="#MathBox"
              title="Permalink to MathBox.MathBox">#</a></h4>
<div class="doc">
<pre class="source">
MathBox();
</pre>
</div>
</div>
</div>
<div>
<h3>Static Properties</h3>
<div class="field"><h4 id="TWO_PI">
<button class="show-code">Code</button>
const double         <strong>TWO_PI</strong> <a class="anchor-link"
            href="#TWO_PI"
            title="Permalink to MathBox.TWO_PI">#</a>
        </h4>
        <div class="doc">
<pre class="source">
static const double TWO_PI = Math.PI * 2.0;
</pre>
</div>
</div>
</div>
<div>
<h3>Static Methods</h3>
<div class="method"><h4 id="distanceSquared">
<button class="show-code">Code</button>
num <strong>distanceSquared</strong>(<a href="../box2d_html/Vector.html">Vector</a> v1, <a href="../box2d_html/Vector.html">Vector</a> v2) <a class="anchor-link" href="#distanceSquared"
              title="Permalink to MathBox.distanceSquared">#</a></h4>
<div class="doc">
<p>Return the distance between the two given vectors, but squared.</p>
<pre class="source">
static num distanceSquared(Vector v1, Vector v2) {
  num dx = (v1.x - v2.x);
  num dy = (v1.y - v2.y);
  return dx * dx + dy * dy;
}
</pre>
</div>
</div>
<div class="method"><h4 id="distance">
<button class="show-code">Code</button>
num <strong>distance</strong>(<a href="../box2d_html/Vector.html">Vector</a> v1, <a href="../box2d_html/Vector.html">Vector</a> v2) <a class="anchor-link" href="#distance"
              title="Permalink to MathBox.distance">#</a></h4>
<div class="doc">
<p>Return the distance between the two given vectors.</p>
<pre class="source">
static num distance(Vector v1, Vector v2) {
  return Math.sqrt(distanceSquared(v1, v2));
}
</pre>
</div>
</div>
<div class="method"><h4 id="clamp">
<button class="show-code">Code</button>
num <strong>clamp</strong>(num a, num low, num high) <a class="anchor-link" href="#clamp"
              title="Permalink to MathBox.clamp">#</a></h4>
<div class="doc">
<p>Returns the closest value to 
<span class="param">a</span> that is in between 
<span class="param">low</span> and 
<span class="param">high</span></p>
<pre class="source">
static num clamp(num a, num low, num high) {
  return Math.max(low, Math.min(a, high));
}
</pre>
</div>
</div>
<div class="method"><h4 id="translateAndScale">
<button class="show-code">Code</button>
num <strong>translateAndScale</strong>(num val, num fromMin, num fromMax, num toMin, num toMax) <a class="anchor-link" href="#translateAndScale"
              title="Permalink to MathBox.translateAndScale">#</a></h4>
<div class="doc">
<p>Given a value within the range specified by 
<span class="param">fromMin</span> and 
<span class="param">fromMax</span>,
returns a value with the same relative position in the range specified
from 
<span class="param">toMin</span> and 
<span class="param">toMax</span>. For example, given a 
<span class="param">val</span> of 2 in the
"from range" of 0-4, and a "to range" of 10-20, would return 15.</p>
<pre class="source">
static num translateAndScale(num val, num fromMin, num fromMax, num toMin,
    num toMax) {
  final num mult = (val - fromMin) / (fromMax - fromMin);
  final num res = toMin + mult * (toMax - toMin);
  return res;
}
</pre>
</div>
</div>
<div class="method"><h4 id="degToRad">
<button class="show-code">Code</button>
num <strong>degToRad</strong>(num deg) <a class="anchor-link" href="#degToRad"
              title="Permalink to MathBox.degToRad">#</a></h4>
<div class="doc">
<p>Convert from 
<span class="param">deg</span> degrees to radians.</p>
<pre class="source">
static num degToRad(num deg) =&gt; (Math.PI / 180.0) * deg;
</pre>
</div>
</div>
<div class="method"><h4 id="radToDeg">
<button class="show-code">Code</button>
num <strong>radToDeg</strong>(num rad) <a class="anchor-link" href="#radToDeg"
              title="Permalink to MathBox.radToDeg">#</a></h4>
<div class="doc">
<p>Convert from 
<span class="param">rad</span> radians to degrees.</p>
<pre class="source">
static num radToDeg(num rad) =&gt; (180.0 / Math.PI) * rad;
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="field inherited"><h4 id="runtimeType">
<button class="show-code">Code</button>
final Type         <strong>runtimeType</strong> <a class="anchor-link"
            href="#runtimeType"
            title="Permalink to MathBox.runtimeType">#</a>
        </h4>
        <div class="inherited-from">inherited from Object </div><div class="doc">
<p>A representation of the runtime type of the object.</p>
<pre class="source">
external Type get runtimeType;
</pre>
</div>
</div>
</div>
<div>
<h3>Operators</h3>
<div class="method inherited"><h4 id="==">
<button class="show-code">Code</button>
bool <strong>operator ==</strong>(other) <a class="anchor-link" href="#=="
              title="Permalink to MathBox.operator ==">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>The equality operator.</p>
<p>The default behavior for all <code>Object</code>s is to return true if and
only if <code>this</code> and 
<span class="param">other</span> are the same object.</p>
<p>If a subclass overrides the equality operator it should override
the <code>hashCode</code> method as well to maintain consistency.</p>
<pre class="source">
bool operator ==(other) =&gt; identical(this, other);
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method inherited"><h4 id="hashCode">
<button class="show-code">Code</button>
int <strong>hashCode</strong>() <a class="anchor-link" href="#hashCode"
              title="Permalink to MathBox.hashCode">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>Get a hash code for this object.</p>
<p>All objects have hash codes. Hash codes are guaranteed to be the
same for objects that are equal when compared using the equality
operator <code>==</code>. Other than that there are no guarantees about
the hash codes. They will not be consistent between runs and
there are no distribution guarantees.</p>
<p>If a subclass overrides <code>hashCode</code> it should override the
equality operator as well to maintain consistency.</p>
<pre class="source">
external int hashCode();
</pre>
</div>
</div>
<div class="method"><h4 id="MathBox">
<button class="show-code">Code</button>
new <strong>MathBox</strong>() <a class="anchor-link" href="#MathBox"
              title="Permalink to MathBox.MathBox">#</a></h4>
<div class="doc">
<pre class="source">
MathBox();
</pre>
</div>
</div>
<div class="method inherited"><h4 id="noSuchMethod">
<button class="show-code">Code</button>
<strong>noSuchMethod</strong>(String name, List args) <a class="anchor-link" href="#noSuchMethod"
              title="Permalink to MathBox.noSuchMethod">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p><code>noSuchMethod</code> is invoked when users invoke a non-existant method
on an object. The name of the method and the arguments of the
invocation are passed to <code>noSuchMethod</code>. If <code>noSuchMethod</code>
returns a value, that value becomes the result of the original
invocation.</p>
<p>The default behavior of <code>noSuchMethod</code> is to throw a
<code>noSuchMethodError</code>.</p>
<pre class="source">
external Dynamic noSuchMethod(String name, List args);
</pre>
</div>
</div>
<div class="method inherited"><h4 id="Object">
<button class="show-code">Code</button>
const <strong>Object</strong>() <a class="anchor-link" href="#Object"
              title="Permalink to MathBox.Object">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>Creates a new <code>Object</code> instance.</p>
<p><code>Object</code> instances have no meaningful state, and are only useful
through their identity. An <code>Object</code> instance is equal to itself
only.</p>
<pre class="source">
const Object();
</pre>
</div>
</div>
<div class="method inherited"><h4 id="toString">
<button class="show-code">Code</button>
String <strong>toString</strong>() <a class="anchor-link" href="#toString"
              title="Permalink to MathBox.toString">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>Returns a string representation of this object.</p>
<pre class="source">
external String toString();
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
